package com.fs.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.common.base.service.AbstractBaseEntityService;
import com.fs.iot.bean.dto.AlarmDefineDTO;
import com.fs.iot.bean.query.AlarmDefineQuery;
import com.fs.iot.domain.entity.AlarmDefineEntity;
import com.fs.iot.domain.mapper.AlarmDefineMapper;
import com.fs.iot.service.AlarmDefineEntityService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 报警定义服务实现 
 * @author Coder Generator 2025-03-24 17:01:43 
 **/
@Service
public class AlarmDefineEntityServiceImpl extends AbstractBaseEntityService<AlarmDefineEntity, AlarmDefineDTO, AlarmDefineMapper, AlarmDefineQuery> implements AlarmDefineEntityService {
    @Override
    protected QueryWrapper<AlarmDefineEntity> queryToWrapper(AlarmDefineQuery query) {
        return this.createQueryWrapper()
                .eq(StringUtils.isNotBlank(query.getId()), "id", query.getId())
                .in(null != query.getIds(), "id", query.getIds())
                .eq(StringUtils.isNotBlank(query.getCategoryId()), "category_id", query.getCategoryId())
                .and(StringUtils.isNotBlank(query.getKey()), w -> {
                    w.like("name", query.getKey())
                            .or(w1 -> w1.like("title", query.getKey()))
                            .or(w1 -> w1.like("content", query.getKey()));
                })
                .orderByDesc("create_time");
    }
}